import {
  mapGetters
} from 'vuex'
export default {
  watch: {
    total: {
      handler(newVal) {
        this.setBadge()
      },
      immediate: true
    }
  },

  onShow() {
    this.setBadge()
  },
  computed: {
    ...mapGetters('m_cart', ['total'])
  },
  methods: {
    setBadge() {
      //调用小程序setTabBarBadge()方法，为购物车右上角添加徽标
      uni.setTabBarBadge({
        index: 2, //索引
        text: this.total + '' //text一定要字符串，因此在后面转化为字符串
      })
    }
  },
}